<template>
  <div class="search">
    <f-form ref="form" :action="api.bmep2" :form-key="this.formItem.materialPlanId">
      <f-form-item label="项目id" name="projectId" hidden="true" :value="formItem.projectId"/>
      <f-form-item label="专业包" name="majorCode" :required="true" :value="formItem.majorCode" type="select" :data="majorData" @change="majorDataChange" />
      <!-- <f-form-item label="专业代码" name="majorCode" ref="majorCode" :required="true" :value="formItem.majorCode" placeholder="-"/> -->
      <f-form-item label="工程包" name="packageNo" :value="formItem.packageNo"  :required="true" type="select" :data="packageData" @change="packageDataChange"/>
      <!-- <f-form-item label="工程包代码" name="packageNo" ref="packageNo" :required="true" :value="formItem.packageNo" placeholder="-"/> -->
      <f-form-item label="材料WBS代码" type="pageSelect" name="materialWbsCode" :showSearch="true"
                   :data="api.wbsarchitecture.page" label-key="wbsCode" :required="true" value-key="wbsCode"
                   :value="formItem.materialWbsCode" :params="{}" />
      <f-form-item label="材料code" type="pageSelect" name="materialCode" :required="true" :showSearch="true"
                   :data="api.materialserice.page" label-key="materialCode" value-key="materialCode"
                   :value="formItem.materialCode" :params="{}"/>
<!--      <f-form-item label="材料名称" name="materialName" :required="true" :value="formItem.materialName"/>-->
      <!-- <f-form-item label="型号,规格" name="materiaSpecs" :required="true" :value="formItem.materiaSpecs"/> -->
      <f-form-item label="项目名称" name="materiaSpecs" :required="true" :value="formItem.materiaSpecs"/>
      <f-form-item label="层级号" name="levelNo" :required="true" :value="formItem.levelNo"/>
      <f-form-item label="指令号" name="instructNumber" :required="true" :value="formItem.instructNumber" v-if="isAdd && type==2"/>
      <f-form-item label="损耗" name="loss" :required="true" :value="formItem.loss"/>
      <f-form-item label="材料项目描述" name="materialDesc" :value="formItem.materialDesc"/>
      <f-form-item label="科目名称" name="subjectName" :value="formItem.subjectName"/>
      <f-form-item label="技术参数" name="technicalData" :value="formItem.technicalData"/>
      <f-form-item label="区域" name="materialArea" :value="formItem.materialArea"/>
      <f-form-item label="系统" name="materialUse" :value="formItem.materialUse"/>
      <f-form-item label="计量单位" name="measurementUnit" :value="formItem.measurementUnit"/>
      <f-form-item label="200预算成本工程量" name="costQuantity200" :value="formItem.costQuantity200"/>
      <!--      <f-form-item label="预估成本主材单价"  name="mainPrice"    :value="formItem.mainPrice" />-->
      <!--      <f-form-item label="有合同主材单价"  name="mainPrice1"    :value="formItem.mainPrice1" />-->
      <!--      <f-form-item label="拟合同主材单价"  name="mainPrice2"    :value="formItem.mainPrice2" />-->
      <!--      <f-form-item label="合同主材单价"  name="mainPrice3"    :value="formItem.mainPrice3" />-->
      <!--      <f-form-item label="预估成本安装单价"  name="installPrice"    :value="formItem.installPrice" />-->
      <!--      <f-form-item label="有合同安装单价"  name="installPrice1"    :value="formItem.installPrice1" />-->
      <!--      <f-form-item label="拟合同安装单价"  name="installPrice2"    :value="formItem.installPrice2" />-->
      <!--      <f-form-item label="合同安装单价"  name="installPrice3"    :value="formItem.installPrice3" />-->
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'
  import apiOther from './js/apiOther'
  import apiconst from '../common/data'
  export default {
    name: 'bmpForm',
    props: {
      type: ''
    },
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, apiOther, this.api),
        majorData: apiconst.majorData,
        packageData: apiconst.packageData,
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          materialPlanId: '',
          projectId: '',
          materialId: '',
          versionId: '',
          packageNo: '',
          majorCode: '',
          serviceCode: '',
          serviceWbsCode: '',
          materialWbsCode: '',
          materialCode: '',
          technicalData: '',
          subjectName: '',
          levelNo: '',
          packageDesc: '',
          contractDesc: '',
          materialArea: '',
          materialUse: '',
          costQuantity100: '',
          costQuantity200: '',
          mainPrice: '',
          mainPrice1: '',
          mainprice2: '',
          mainprice3: '',
          installPrice: '',
          installPrice1: '',
          installPrice2: '',
          installPrice3: '',
          contractInstallPrice1: '',
          contractInstallPrice2: '',
          contractInstallPrice3: '',
          createTime: '',
          updateTime: '',
          majorName: '',
          packageName: '',
          loss: '',
          measurementUnit: '',
          instructNumber: ''

        }
      },
      //表单赋值
      setData(data) {
        // this.$refs.form.resetFields()
        // this.formItem = this.getFormItem()
        this.formItem.projectId = data
        if (data && data.materialPlanId) {
          let params = {
            materialPlanId: data.materialPlanId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.formItem['handlerName'] = 'busMaterialPlan200SaveHandler'
        this.$refs.form.submit( this.formItem, callback)
      },
      majorDataChange(val) {
        const record = this.majorData.filter(item => item.value == val);
        this.formItem['majorName'] = (record!=null && record.length>0)?record[0].name:null
        // this.$refs.majorCode.value = val
      },
      packageDataChange(val) {
        const record = this.packageData.filter(item => item.value == val);
        this.formItem['packageName'] = (record!=null && record.length>0)?record[0].name:null
        // this.$refs.packageNo.value = val
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
